package com.zengqingfa.juc.n4.lock8;

import lombok.extern.slf4j.Slf4j;

/**
 * @fileName: ThreadLock6
 * @author: zengqf3
 * @date: 2021-6-10 9:41
 * @description:
 */
@Slf4j(topic = "c.ThreadLock6")
public class ThreadLock6 {

    public synchronized static void method1() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.debug("method1....");
    }

    public synchronized static void method2() {
        log.debug("method2....");
    }


    public static void main(String[] args) {
        /**
         * 10:08:35:233 [Thread-0] c.ThreadLock6 - method1....
         * 10:08:35:238 [Thread-1] c.ThreadLock6 - method2....
         * 或者
         * 10:08:56:631 [Thread-1] c.ThreadLock6 - method2....
         * 10:10:56:625 [Thread-0] c.ThreadLock6 - method1....
         */
        ThreadLock6 lock1 = new ThreadLock6();
        new Thread(() -> {
            lock1.method1();
        }).start();
        new Thread(() -> {
            lock1.method2();
        }).start();

    }
}
